package com.rabbitmq.exec.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.exec.utils.RabbitMqUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author lhj
 * @Date 2024/4/13 16:38
 */
public class Worker02 {
    static Logger logger = LoggerFactory.getLogger(Worker02.class);
    public static final String QUEUE_NAME = "hello";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        
        logger.info("消费者02等待接收: {}, 的消息", QUEUE_NAME);
        
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            String msg = new String(message.getBody(), "UTF-8");
            logger.info("消费者Worker02 接收到: {}队列的消息: {}", QUEUE_NAME, msg);
        };
        
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, (consumerTag) -> {});
        
    }
    
}
